package com.core.family.biz.yizhao.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.core.common.utils.JwtUtil;
import com.core.family.admin.domain.dto.SysUserDto;
import com.core.family.admin.domain.po.PlatUser;
import com.core.family.admin.service.PlatUserService;
import com.core.family.admin.service.SysUserService;
import com.core.family.biz.yizhao.domain.dto.YzUserDto;
import com.core.family.biz.yizhao.domain.po.YzUserExtend;
import com.core.family.biz.yizhao.mapper.YzUserExtendMapper;
import com.core.family.biz.yizhao.service.YzUserExtendService;
import com.core.family.springUtils.ApplicationUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;
import java.util.Objects;

import com.core.common.gen.BaseServiceImpl;



/**
 * @author honglei
 * @version 1.0
 * @time: 2023-7-4 11:47:40
 * @Description 服务实现层 一招用户扩展
 */
@Slf4j
@Service
public class YzUserExtendServiceImpl extends BaseServiceImpl<YzUserExtendMapper, YzUserExtend> implements YzUserExtendService {


    @Override
    public YzUserDto getYzUserByToken(String token) {

        if (!JwtUtil.validateToken(token)) {
            return null;
        }
        String id = JwtUtil.getId(token);
        return getDetailById(id);
    }

    @Override
    public YzUserDto getDetailById(Serializable id) {
        if (Objects.isNull(id)){
            return null;
        }
        YzUserDto dto=new YzUserDto();
        PlatUserService service = ApplicationUtil.getBean(PlatUserService.class);
        PlatUser platUser =  service.getById(id);
        if (Objects.isNull(platUser) || null ==platUser.getId()){
            return null;
        }
        BeanUtils.copyProperties(platUser,dto);
        YzUserExtend extend = getById(dto.getId());
        if (Objects.nonNull(extend)){
            BeanUtils.copyProperties(extend,dto);
        }
        return  dto;
    }

}

